package com.neu.controller;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

import com.neu.dao.TeacherDao;
import com.neu.daoimpl.TeacherDaoImpl;
import com.neu.entity.Teacher;

public class TeacherManager {
private static Scanner sc=new Scanner(System.in);
public static void main(String[] args) throws SQLException{
	System.out.println("===========欢迎教师系统==========");
	while(true) {
//		selectOperation();
		selectOperation1();
	}
}
public static void selectOperation1() throws SQLException {
	TeacherDao tc = new TeacherDaoImpl();
	Teacher stu = null;
	System.out.println("请输入操作信息:");
	System.out.println("1.修改个人的信息:");
	System.out.println("2.查看个人的信息:");
	System.out.println("3.退出系统;");
	int i = sc.nextInt();
	switch(i) {
	case 1:
		 System.out.println("请输入您要修改个人信息的编号:");
		 int c = sc.nextInt();
		 System.out.println("请输入您要修改的姓名");
		 String d = sc.next();
		 System.out.println(tc.updateTeacher(new Teacher(c, d)));
		 break;
	case 2:
		 System.out.println("请输入你要查询个人信息的编号:");
		 int e = sc.nextInt();
			 System.out.println(tc.finfByNameOrId(new Teacher(e,null)));
			 break;
	case 3:
		 System.out.println("=========谢谢使用教师管理系统========");
		 System.exit(0);
		 break;
		 default:
			 System.out.println("无操作项");
	}
}
public static void selectOperation() throws SQLException {
	//  因为  TeacherDao  是一个接口,不是类  不能直接实例化
	  //         所以必须通过它的子类来实例化    TeacherDaoImpl()就是 TeacherDao 的子类
	TeacherDao tc = new TeacherDaoImpl();
	
	Teacher stu = null;
	 System.out.println("请输入操作信息：  ");
	 System.out.println("1.添加教师");
	 System.out.println("2.删除教师");
	 System.out.println("3.修改教师");
	 System.out.println("4.查询单个教师信息");
	 System.out.println("5.查询所有教师信息");
	 System.out.println("6.退出系统");
	 int i = sc.nextInt();
	 switch(i) {
	 case 1:
		 //    通过 对象调用方法名   因为对象是  tc  所以直接      对象名.方法名调用
		 //     添加学生信息
		 System.out.println("选择你要添加的姓名");
		 String a = sc.next();
		 System.out.println(tc.addTeacher(new Teacher(0, a)));
		 break;
	 case 2:
		 // 删除教师:
		 try {
			 System.out.println("输入你要删除老师对应的编号:");
			 int b = sc.nextInt();
			System.out.println(tc.deleteTeacher(new Teacher(b, null)));
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 break;
	 case 3:
		 // 修改教师:
		 System.out.println("请输入您要修改老师的编号:");
		 int c = sc.nextInt();
		 System.out.println("请输入您要修改的老师的姓名");
		 String d = sc.next();
		 System.out.println(tc.updateTeacher(new Teacher(c, d)));
		 break;
	 case 4 :
		 // 查询单一的教师信息:
//		 System.out.println("1.请输入您要查询教师的编号:");
//		 System.out.println("2.请输入您要查询教师信息的姓名:");
//		 int n = sc.nextInt();
//		 switch(n) {
//		 
//		 case 1:
//			 System.out.println("请输入你要查询的编号:");
//			int id= sc.nextInt();
		 System.out.println("请输入你要查询老师的编号:");
		 int e = sc.nextInt();
			 System.out.println(tc.finfByNameOrId(new Teacher(e,null)));
			 break;
//		 case 2:
//			 System.out.println("请输入你要查询的名字:");
//			 String name = sc.next();
//			 System.out.println(tc.finfByNameOrId(new Teacher(0,name)));
//			 break;
//		 }
	 case 5 :
		 //  查询所以的教师信息:
		 List<Teacher> list=tc.selectTeachers();
		 //遍历集合，显示信息
		 Iterator<Teacher> ite=list.iterator();
		 while(ite.hasNext()) {
			 stu=ite.next();
			 System.out.println(stu);
		 }
		 break;
	 case 6:
		 System.out.println("=========谢谢使用教师管理系统========");
		 System.exit(0);
		 break;
		 default:
			 System.out.println("无操作项");
	 }
}
}
